home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / misc / emu / arosdev.lha / AROS / rom / utility / checkdate.c < prev    next >
C/C++ Source or Header  |  1997-02-03  |  3KB  |  128 lines

  1. /*
  2.     Copyright (C) 1995-1997 AROS - The Amiga Replacement OS
  3.     $Id: checkdate.c,v 1.4 1997/02/03 02:58:31 ldp Exp $
  4.  
  5.     Desc: CheckDate() - is a date valid ?
  6.     Lang: english
  7. */
  8. #include "utility_intern.h"
  9.  
  10. /*****************************************************************************
  11.  
  12.     NAME */
  13. #include <utility/date.h>
  14. #include <proto/utility.h>
  15.  
  16.         AROS_LH1(ULONG, CheckDate,
  17.  
  18. /*  SYNOPSIS */
  19.         AROS_LHA(struct ClockData *, date, A0),
  20.  
  21. /*  LOCATION */
  22.         struct Library *, UtilityBase, 22, Utility)
  23.  
  24. /*  FUNCTION
  25.         Examine the date described in the ClockData structure and
  26.         determine whether it is a valid date. In particular this
  27.         checks whether the ranges of the fields are within normal
  28.         limits.
  29.  
  30.         This function does not check whether the wday field of the
  31.         ClockData structure is valid.
  32.  
  33.     INPUTS
  34.         date        -   A ClockData structure desribing the date
  35.                         to check.
  36.  
  37.     RESULT
  38.         If the date is valid, the number of seconds from midnight
  39.         1-Jan-1978 AD to the date, or 0 if the date is invalud.
  40.  
  41.     NOTES
  42.         The date 01-Jan-78 00:00:00 is actually returned as invalid.
  43.  
  44.         This also assumes that the ClockDate refers to a date in the
  45.         Gregorian calendar. (60 sec/min, 60 min/hour, 24 hr/day,
  46.         12 months/year).
  47.  
  48.     EXAMPLE
  49.  
  50.     BUGS
  51.         Does not check whether the 29/2 is valid outside of a leap year.
  52.  
  53.     SEE ALSO
  54.         Amiga2Date(), Date2Amiga()
  55.  
  56.     INTERNALS
  57.         Since all the values are unsigned, we don't have to check for < 0
  58.         in fields which range from 0 ... n.
  59.  
  60.     HISTORY
  61.         29-10-95    digulla automatically created from
  62.                             utility_lib.fd and clib/utility_protos.h
  63.  
  64. *****************************************************************************/
  65. {
  66.     AROS_LIBFUNC_INIT
  67.  
  68.     /* Note: 60!!! This is in case of any future leap seconds... */
  69.     if( date->sec > 60 )
  70.         return 0;
  71.  
  72.     if( date->min > 59)
  73.         return 0;
  74.  
  75.     if( date->hour > 23)
  76.         return 0;
  77.  
  78.     /* XXX: When does the year become invalid? */
  79.     if( date->year < 1978 )
  80.         return 0;
  81.  
  82.     if( date->wday > 6)
  83.         return 0;
  84.  
  85.     if( date->mday < 1 )
  86.         return 0;
  87.  
  88.     switch( date->month )
  89.     {
  90.         /* 30 days hath April, September, June and November */
  91.         case 4:
  92.         case 6:
  93.         case 9:
  94.         case 11:
  95.             if(date->mday > 30)
  96.                 return 0;
  97.             break;
  98.  
  99.         /* And all the rest have 31 ... */
  100.         case 1:
  101.         case 3:
  102.         case 5:
  103.         case 7:
  104.         case 8:
  105.         case 10:
  106.         case 12:
  107.             if(date->mday > 31)
  108.                 return 0;
  109.             break;
  110.  
  111.         /*  Except February with has 28, or 29 on a leap year,
  112.             should I check whether this is a leap year or not?
  113.         */
  114.         case 2:
  115.             if(date->mday > 29)
  116.                 return 0;
  117.             break;
  118.  
  119.         /* This also traps invalid month numbers */
  120.         default:
  121.             return 0;
  122.     } /* switch(date->month) */
  123.  
  124.     return Date2Amiga(date);
  125.  
  126.     AROS_LIBFUNC_EXIT
  127. } /* CheckDate */
  128.